package fms.models;

import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;

import fms.classes.TestClass;

public class TestDAO {
	
	private SqlSessionFactory sqlSessionFactory;

	public TestDAO(){
		sqlSessionFactory = MyBatisSqlConnection.getSqlSessionFactory();
	}
	
	
	public TestClass selectTestClass(int testNum){
		
		SqlSession session = sqlSessionFactory.openSession();
		try{
			TestClass testClass = (TestClass) session.selectOne("TestClass.getTest", testNum);
			return testClass;
		}finally{
			session.close();
		}
	}
	
	public void insertTestClass(TestClass testClass){
		
		SqlSession session = sqlSessionFactory.openSession();
		
		try{
			try{
			session.insert("TestClass.insertTestUser", testClass);
			session.commit();
			}catch(Exception e){ System.out.println("\n\n no luck .. did not succeed TestClass.insertTestUser"); e.printStackTrace();}
		} finally{
			session.close();
		}
	}
}
